package com.hcy.common.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.hcy.common.CommonInfoBz;
import com.hcy.common.dto.CarLevelPriceConfig;
import com.hcy.common.entity.GaodeGfids;
import com.hcy.rabbitbasicutils.utils.RedisUtils;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/3/12 10:27
 */
@Component
@Data
public class RuntimeConfig {

    @Autowired
    private CommonInfoBz commonInfoBz;
    @Autowired
    RedisUtils redisUtils;
    static Logger logger = LoggerFactory.getLogger(RuntimeConfig.class);

    /**
     * 车辆价格配置
     */
    private final Map<String, CarConfigDetails> carConfigDetailsMap = new HashMap<>();

    /**
     * 地图围栏
     */
    private List<GaodeGfids> gaodeGfids = new ArrayList<>();

    @PostConstruct
    public void loadConfig() {
        logger.info("load bz car config start...");
        //获取车辆价格配置
        List<CarLevelPriceConfig> config = commonInfoBz.getCarLevelPriceConfig();
        for (CarLevelPriceConfig carLevelPriceConfig : config) {
            CarConfigDetails carConfigDetails = new CarConfigDetails();
            carConfigDetails.setConfig(carLevelPriceConfig);
            //以后要添加其他关于车辆的本地缓存可在此做集成
            carConfigDetailsMap.put(carLevelPriceConfig.getLabel(), carConfigDetails);
        }
        //获取地图围栏
        gaodeGfids = commonInfoBz.getGfids();
        redisUtils.hPut("carConfigDetailsMap","gaodeGfids", JSON.toJSONString(gaodeGfids));
    }

}
